home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Emulators / v2600 / Source.lha / Source / collision.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-25  |  2.5 KB  |  105 lines

  1. /*****************************************************************************
  2.  
  3.    This file is part of x2600, the Atari 2600 Emulator
  4.    ===================================================
  5.    
  6.    Copyright 1996 Alex Hornby. For contributions see the file CREDITS.
  7.  
  8.    This software is distributed under the terms of the GNU General Public
  9.    License. This is free software with ABSOLUTELY NO WARRANTY.
  10.    
  11.    See the file COPYING for details.
  12.    
  13.    Tweaked by Matthew Stroup for Amiga v2600, January 27, 1997.
  14.  
  15. ******************************************************************************/
  16.  
  17. /* The 2600 collision detection code */
  18.  
  19. #include <stdlib.h>
  20. #include "types.h"
  21. #include "col_mask.h"
  22.  
  23. /*
  24.    There are 6 different objects on the screen. Each takes one bit of the 
  25.    collision vector.
  26.    Bit 0: Player 0
  27.    Bit 1: Player 1
  28.    Bit 2: Missile 0
  29.    Bit 3: Missile 1
  30.    Bit 4: Ball
  31.    Bit 5: Playfield
  32.  */
  33.  
  34. /* The collision vector */
  35. UBYTE *colvect;
  36.  
  37. /* The collision lookup table */
  38. unsigned short col_table[256];
  39.  
  40. /* The collision state */
  41. unsigned short col_state;
  42.  
  43. /* Resets the collision registers of the tia */
  44. __inline void reset_collisions (void)
  45. {
  46.   col_state=0;
  47. }
  48.  
  49. /* Does collision testing on the pixel b */
  50. /* b: byte to test for collisions */
  51. /* Used to build up the collision table */
  52. int set_collisions (UBYTE b)
  53. {
  54.   int res=0;
  55.  
  56.   if ((b & ML0_MASK) && (b & PL1_MASK))
  57.     res |= M0P1_MASK;
  58.   if ((b & ML0_MASK) && (b & PL0_MASK))
  59.     res |= M0P0_MASK;
  60.   if ((b & ML1_MASK) && (b & PL0_MASK))
  61.     res |=  M1P0_MASK;
  62.   if ((b & ML1_MASK) && (b & PL1_MASK))
  63.     res |=  M1P1_MASK;
  64.  
  65.   if ((b & PL0_MASK) && (b & PF_MASK))
  66.     res |= P0PF_MASK; 
  67.   if ((b & PL0_MASK) && (b & BL_MASK))
  68.     res |= P0BL_MASK;
  69.   if ((b & PL1_MASK) && (b & PF_MASK))
  70.     res |= P1PF_MASK ;
  71.   if ((b & PL1_MASK) && (b & BL_MASK))
  72.     res |= P1BL_MASK;
  73.  
  74.   if ((b & ML0_MASK) && (b & PF_MASK))
  75.     res |=  M0PF_MASK;
  76.   if ((b & ML0_MASK) && (b & BL_MASK))
  77.     res |= M0BL_MASK;
  78.   if ((b & ML1_MASK) && (b & PF_MASK))
  79.     res |=  M1PF_MASK; 
  80.   if ((b & ML1_MASK) && (b & BL_MASK))
  81.     res |=  M1BL_MASK;
  82.  
  83.   if ((b & BL_MASK) && (b & PF_MASK))
  84.     res |=BLPF_MASK;
  85.   if ((b & PL0_MASK) && (b & PL1_MASK))
  86.     res |=P0P1_MASK ;
  87.   if ((b & ML0_MASK) && (b & ML1_MASK))
  88.     res |=M0M1_MASK ;
  89.  
  90.   return res;
  91. }
  92.  
  93.  
  94. void init_collisions(void)
  95. {
  96.   int i;
  97.  
  98.   /* Set up the collision lookup table */ 
  99.   for (i = 0; i < 256; i++)
  100.     col_table[i] = set_collisions(i);
  101.  
  102.   /* Get the colvect 8 byte aligned */
  103.   colvect=(UBYTE *)calloc(28, 8);
  104. }
  105.